package cn.wolfcode.controller;

import cn.wolfcode.domain.vo.InfoTemp;
import cn.wolfcode.service.IChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * 智能客服控制层
 */

@RestController // 将当前类创建对象并纳入到 Spring 容器中。 只返回数据不返回页面
@RequestMapping("/api/ai")
public class ChatController {

    @Autowired
    private IChatService chatService;

    /**
     * value = "/chat"  请求地址
     * produces = MediaType.TEXT_EVENT_STREAM_VALUE 流式响应
     */
    @PostMapping(value = "/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> chat(@RequestBody InfoTemp infoTemp) {
        // 调用业务层来处理请求
        Flux<String> result = chatService.chat(infoTemp);
        return result;
    }
}